﻿<%@ WebHandler Language="C#" Class="MapHandler" %>

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using Business.Common;
using Business.Map;
using Business.Map.Model;
using WF_Business;
using WF_DataAccess;

public class MapHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var action = context.Request["action"];
        var bdcId = context.Request["bdcId"];
        var strPoint = context.Request["point"];
        var strName = context.Request["name"];
        var xmiid = context.Request["xmiid"];
        var strMarkAttr = context.Request["markAttr"];
        var dataType = context.Request["dataType"];
        var purpose = context.Request["purpose"];
        context.Response.ContentType = "text/plain";
        switch (action)
        {
            case "Save":
                context.Response.Write(Save(strPoint, strName, xmiid, strMarkAttr, dataType, purpose));
                break;
            case "Delete":
                context.Response.Write(MapBLL.Delete(bdcId));
                break;
            default:
                context.Response.Write("action参数错误");
                break;
        }
    }

    private static string Save(string point, string name, string xmiid, string markattr, string dataType, string purpose)
    {
        var bdcId = Guid.NewGuid().ToString("N");
        var ida = SysParams.OAConnection(true);
        try
        {
            MapBLL.InsertTbMarkInfo(ida, bdcId, name, xmiid, markattr, dataType, purpose);
            point.StrToList('|').ForEach(c =>
            {
                var arrPoint = c.StrToArr();
                var pointX = arrPoint[0];
                var pointY = arrPoint[1];
                MapBLL.InsertTbMarkLocation(ida, bdcId, pointX, pointY);
            });
            ida.Close(true);
            var result = new MapResult
            {
                ResultInfo = "保存成功",
                FormId = MapBLL.GetFormId(dataType),
                BdcId = bdcId
            };
            return result.T2Json();
        }
        catch (Exception ex)
        {
            ida.Close(false);
            var result = new MapResult { ResultInfo = "保存失败:" + ex.Message };
            return result.T2Json(); ;
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}